/**
 * Please modify this class to meet your needs
 * This class is not complete
 */

package org.kallsonys.oms.ws.customerservices;

import java.util.logging.Logger;

import org.kallsonnys.oms.dto.CustomerDTO;
import org.kallsonnys.oms.dto.security.IntialCustomerLoginDTO;
import org.kallsonnys.oms.services.customers.CustomersFacadeRemote;
import org.kallsonys.oms.commons.Exception.OMSException;
import org.kallsonys.oms.commons.locator.ServiceLocator;
import org.kallsonys.oms.ws.mapper.WSMapper;

import com.integration.kallsonys.kallsonysschema.types.Customer;
import com.integration.kallsonys.kallsonysschema.types.CustomerInfoEmail;
import com.integration.kallsonys.kallsonysschema.types.InitialLoginDTO;
import com.integration.kallsonys.kallsonysschema.types.LoginDTO;

/**
 * This class was generated by Apache CXF 2.6.3 2013-10-24T00:33:17.349-05:00
 * Generated source version: 2.6.3
 * 
 */

@javax.jws.WebService(serviceName = "CustomerServices", portName = "CustomerServicesSOAP", targetNamespace = "http://ws.oms.kallsonys.org/customerservices", wsdlLocation = "file:/Users/macbook/Documents/BUS-KallsonnysOMS-WS/war/WEB-INF/wsdl/customerServices.wsdl", endpointInterface = "org.kallsonys.oms.ws.customerservices.CustomerServices")
public class CustomerServicesImpl implements CustomerServices {

	private static final Logger logger = Logger
			.getLogger(CustomerServicesImpl.class.getName());

	public InitialLoginDTO getInitialLoginInfo(LoginDTO getInitialLoginRequest)
			throws GetInitialLoginInfoFault {

		try {

			logger.info("getInitialLoginInfo:Operation start");

			CustomersFacadeRemote customersFacadeRemote = ServiceLocator
					.getInstance().getRemoteObject("CustomersBean");

			IntialCustomerLoginDTO customerLogin = customersFacadeRemote
					.getInitialLoginInfo(getInitialLoginRequest.getUserUid(),
							getInitialLoginRequest.getPassword());

			InitialLoginDTO initialLoginDTO = new InitialLoginDTO();

			initialLoginDTO.setCustomerInfo(WSMapper.mapCustomer(customerLogin.getCustomer()));
			initialLoginDTO.setTgt(customerLogin.getServiceTicket());

			return initialLoginDTO;

		} catch (java.lang.Exception ex) {
			 ex.printStackTrace();
			if(ex.getCause() instanceof OMSException){
				 throw new GetInitialLoginInfoFault(ex.getCause().getMessage());
			}
            throw new GetInitialLoginInfoFault("OCURRIO UN ERROR INESPERADO EN LISTADO DE LAS ORDENES");
        }finally {
			logger.info("getInitialLoginInfo:Operation finish");
		}

	}

	public Customer createCustomer(Customer customer)
			throws CreateCustomerFault {

		try {

			logger.info("createCustomer:Operation start");

			CustomersFacadeRemote customersFacadeRemote = ServiceLocator
					.getInstance().getRemoteObject("CustomersBean");

			customersFacadeRemote.createCustomer(WSMapper
					.mapCustomerDTO(customer));

			return customer;

		} finally {
			logger.info("createCustomer:Operation finish");
		}
	}

	public Customer getCustomerInfo(CustomerInfoEmail getCustomerInfoRequest)
			throws GetCustomerInfoFault {
		try {

			logger.info("getCustomerInfo:Operation start");

			CustomersFacadeRemote customersFacadeRemote = ServiceLocator
					.getInstance().getRemoteObject("CustomersBean");

			CustomerDTO customerDTO = customersFacadeRemote.getCustomerDetail(getCustomerInfoRequest.getEmail());
			
			return WSMapper.mapCustomer(customerDTO);
			

		} finally {
			logger.info("getCustomerInfo:Operation finish");
		}
	}

	public Customer updateCustomer(Customer updateCustomerResquest)
			throws UpdateCustomerFault {
		try {

			logger.info("getCustomerInfo:Operation start");

			CustomerDTO customerDTO = WSMapper.mapCustomerDTO(updateCustomerResquest);
			
			CustomersFacadeRemote customersFacadeRemote = ServiceLocator
					.getInstance().getRemoteObject("CustomersBean");
			
			return WSMapper.mapCustomer(customersFacadeRemote.updateCustomer(customerDTO));
		} finally {
			logger.info("getCustomerInfo:Operation finish");
		}
	}

}
